
$(function(){
	var table1= $('#sample_1').DataTable({
		"bFilter":false,	
		"bProcessing": false,
		"dom": '<f<t>ilrp>',  
		"ordering":false,
		"aaSorting" : [ [ 3, "desc" ] ],//默认第几个排序
		"bStateSave": true,//状态保存
		"bPaginate": true, //翻页功能
		"aoColumnDefs": [
		  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
		  {"orderable":false,"aTargets":[0,1,2]}// 制定列不参与排序
		],
		"showRowNumber":true,
		"oLanguage" : {
			"sProcessing" : "&nbsp;&nbsp;&nbsp;&nbsp;正在加载数据...",
				"sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "sZeroRecords": "没有检索到数据",
                 "sSearch": "搜索：",
                "oPaginate": {
                    "sPrevious": "上一页",
                    "sNext": "下一页",
					"zeroRecords": "没有找到记录",
                 	"info": "第 _PAGE_ 页 ( 总共 _PAGES_ 页 )",
                    "infoEmpty": "无记录",
                }
		},
		"bDeferRender" : true,
		"aoColumns" : [{
			"mData" : "uname"
		},{
			"mData" : "uclass"
		},{
			"mData" : "userid"
		}],
		"bServerSide" : true,
		"sAjaxSource" : "getDormitoryAbsence",
		"fnServerData" : function(sSource, aoData,
				fnCallback) {
			$.ajax({
				"type" : 'post',
				"url" : sSource,
				"dataType" : "json",
				"data" : {
					aoData : JSON.stringify(aoData),
					"ptime":$("#serm_time").val(),
					"btime":$("#serm_time1").val(),
					"classname":$("#classlist").val()
				},
				"success" : function(resp) {
					fnCallback(resp);
				}
			});
		},
	//	"fnRowCallback" : function(nRow, aData,index) {
			//$('td:eq(4)',nRow).html("<input type=\"checkbox\" value='"+aData.ID+"' name=\"choose\" />");
		//	$('td:eq(3)',nRow).html("<button class='btn btn-danger btn-xs calt_sign' onclick=\"repair("+aData.duserid+")\">补签</button>");
//		}
		

    });
		    	    
	var table2=$('#sample_2').DataTable({
		"bFilter":false,
		"dom": '<f<t>ilrp>',  
		"ordering":false,
		"aaSorting" : [ [ 3, "desc" ] ],//默认第几个排序
		"bStateSave": true,//状态保存
		"bPaginate": true, //翻页功能
		"aoColumnDefs": [
		  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
		  {"orderable":false,"aTargets":[0,1,2]}// 制定列不参与排序
		],
		"showRowNumber":true,
		"oLanguage" : {
				"sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "sZeroRecords": "没有检索到数据",
                 "sSearch": "搜索：",
                "oPaginate": {
                    "sPrevious": "上一页",
                    "sNext": "下一页",
					"zeroRecords": "没有找到记录",
                 	"info": "第 _PAGE_ 页 ( 总共 _PAGES_ 页 )",
                    "infoEmpty": "无记录",
                }
		},
		"bDeferRender" : true,
		"aoColumns" : [{
			"mData" : "uname"
		},{
			"mData" : "uclass"
		},{
			"mData" : "duserid"
		},{
			"mData" : "dsigntime"
		}],
		"bProcessing" : true,
		"bServerSide" : true,
		"sAjaxSource" : "getDomitoryCome",
		"fnServerData" : function(sSource, aoData,
				fnCallback) {
			$.ajax({
				"type" : 'post',
				"url" : sSource,
				"dataType" : "json",
				"data" : {
					aoData : JSON.stringify(aoData),
					"ptime":$("#serm_time").val(),
					"btime":$("#serm_time1").val(),
					"classname":$("#classlist").val()
				},
				"success" : function(resp) {
					fnCallback(resp);
				}
			});
		},
		"fnRowCallback" : function(nRow, aData,index) {
		}
		});
    var str=$("#classlist").html();
    jQuery('#sample_'+1+'_wrapper .dataTables_length select').addClass("form-control"); // modify table search input
    jQuery('#sample_'+2+'_wrapper .dataTables_length select').addClass("form-control"); // modify table search input
  //  $(".dataTables_length").eq(0).parent().append("<span style='float:left;padding-top:15px'>班级：<select style='width:130px;' class='form-control'>"+str+"</select>&nbsp;&nbsp;   签到起始时间段：<input id='serm_time' class='form-control text-box' name='act_start_time' type='text' readonly='readonly' placeholder='起始时间'> —— <input id='serm_time1' class='form-control text-box' name='act_stop_time'  type='text' readonly='readonly' placeholder='结束时间'>&nbsp;&nbsp; <button class='btn btn-success' onclick='searchUnsigned()'>搜 索</button>");
    $(".dataTables_length").eq(0).parent().append("<span style='float:left;padding-top:15px;'>寝室点名未签到同学</span>");

    $(".dataTables_length").eq(1).parent().append("<span style='float:left;padding-top:15px;'>寝室点名已签到同学</span>");
    $("input[name='act_start_time'],input[name='act_stop_time']" ).datetimepicker({maxDate : -0,});	

    $("#search").click(function() {
    	var nsendtime=$("#serm_time").val();
    	var ndeadline=$("#serm_time1").val();
    	var date1=nsendtime.split(' ')[0];
    	var date2=ndeadline.split(' ')[0];
    	var dt1 = new Date(Date.parse(date2));
    	var dt2= new Date(Date.parse(date1));
    	var diff = parseInt((dt1.getTime() - dt2.getTime()) / (1000 * 60 * 60 * 24));
    	if(nsendtime=="" || ndeadline=="")
    		{
    			layer.alert("请完整填写时间段！");
    			return 0;
    		}
    	else if(nsendtime>ndeadline)
    	{
    		layer.alert("签到结束时间必须大于签到起始时间！");
    		return 0;
    	}else if(diff>2)
    		{
    			layer.alert("签到起始时间差必须在2天之内！");
    		}
    	else{
           //window.location.reload();
//    		table1.api().ajax.reload();
//    		table2.api().ajax.reload();
//    		table1.draw();
//    		table2.draw();
    		//以上几种方案不可行
    		table1.fnClearTable(0);
     		table1.fnDraw();
     		table2.fnClearTable(0);
     		table2.fnDraw();
    	}
    });

});




